/**
 * 
 */
package org.t2.backstage.module.player.model;

import org.banish.sql.core.annotation.Column;
import org.banish.sql.core.annotation.Id;
import org.banish.sql.core.annotation.Index;
import org.banish.sql.core.annotation.Table;
import org.banish.sql.core.annotation.Id.Strategy;
import org.banish.sql.core.annotation.enuma.IndexType;
import org.gaming.service.repository.annotation.NoCache;
import org.gaming.service.service.redis.OneToManyEntity;
import org.springframework.stereotype.Repository;

/**
 * @author YY
 */
@Repository
@NoCache
@Table(comment = "IP封禁表", dbAlias = "backdata", indexs = {
		@Index(fields = { "ip" }, type = IndexType.UNIQUE) })
public class ForbidIp extends OneToManyEntity {
	@Id(strategy = Strategy.AUTO)
	@Column(comment = "数据ID")
	private long id;
	@Column(comment = "IP地址")
	private String ip;
	@Column(comment = "操作人ID")
	private long userId;
	@Column(comment = "操作人名字")
	private String userName;
	@Column(comment = "备注")
	private String remark;

	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public String getIp() {
		return ip;
	}

	public void setIp(String ip) {
		this.ip = ip;
	}

	public long getUserId() {
		return userId;
	}

	public void setUserId(long userId) {
		this.userId = userId;
	}

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	@Override
	public Long redisHashKey() {
		return ipToLong(ip);
	}

	public static void main(String[] args) {
		System.out.println(ipToLong("127.0.0.1"));
		System.out.println(ipToLong("36.159.191.128"));
	}

	public static long ipToLong(String ip) {
		try {
			String[] parts = ip.split("\\.");
			long result = 0;
			long offset = 1;
			for (int i = parts.length - 1; i >= 0; i--) {
				int value = Integer.parseInt(parts[i]);
				result += value * offset;
				offset *= 1000;
			}
			return result;
		} catch (Exception e) {
			return 0;
		}
	}

	@Override
	public Long redisOwnerKey() {
		return 0L;
	}
}
